import axios from 'axios';

import {ALL_SERVICE_API} from '../api';
var qs = require('qs');
// 路径
const NEW_STM_DICTS = ALL_SERVICE_API + '/dicts';

const NEW_STM_DICT_BY_ID = ALL_SERVICE_API + '/dicts/';

const NEW_STM_DICT_ENTITYS = ALL_SERVICE_API + '/dict-entities';
const NEW_STM_DICT_ENTITY_BY_ID = ALL_SERVICE_API + '/dict-entities/';
const NEW_STM_DICT_ENTITY_MODIFY_ENABLED = ALL_SERVICE_API + '/stm_dict_entity_modify_enabled';
const NEW_STM_DICT_ENTITY_BY_DICTCODE = ALL_SERVICE_API + '/dict-entitys/by/dict-code';

// 获取数字字典列表
export const searchDictList = params => {
  return axios.get(NEW_STM_DICTS, {params: params});
};

// 保存数字字典
export const saveStmDict = (params) => {
  return axios.put(NEW_STM_DICTS, params);
};
// 删除数字字典
export const deleteStmDict = id => {
  return axios.delete(NEW_STM_DICT_BY_ID + id);
};
// 获取数字字典详情列表
export const searchDictListDetail = params => {
  return axios.get(NEW_STM_DICT_ENTITYS, {params: params});
};
// 保存数字字典
export const saveStmDictDetail = (params) => {
  return axios.put(NEW_STM_DICT_ENTITYS, params);
};
// 删除数字字典详情
export const deleteStmDictDetail = id => {
  return axios.delete(NEW_STM_DICT_ENTITY_BY_ID + id);
};
// 批量启用/停用
export const batchStart = (id, enabled) => {
  return axios.post(NEW_STM_DICT_ENTITY_MODIFY_ENABLED, qs.stringify({id: id, enabled: enabled}));
};

// 查询字典项
export const searchDictEntitys = id => {
  return axios.get(NEW_STM_DICT_ENTITY_BY_DICTCODE, {params: {dictCode: id}});
};
